package com.sun.sangeng.mytest;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class StreamTest {

    public static void main(String[] args) {
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5);
        Optional<Integer> reduce = integerStream
                .parallel() 
                .peek(integer -> System.out.println(Thread.currentThread().getName()+"  integer = "+integer))
                .filter(num -> num > 2)
                .reduce((result, element) -> result + element);
        reduce.ifPresent(System.out::println);
        
    }
}
